package cn.tedu.kcircle.detail.infra.repository.persist;

import cn.tedu.kcircle.detail.dao.entity.DetailDO;
import cn.tedu.kcircle.detail.dao.mapper.DetailMapper;
import cn.tedu.kcircle.detail.infra.converter.DetailConverter;
import cn.tedu.kcircle.detail.repository.model.DetailAddModel;
import cn.tedu.kcircle.detail.repository.persist.DetailRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Repository;

@Repository
@AllArgsConstructor
public class DetailRepositoryImpl implements DetailRepository {
    private DetailMapper detailMapper;
    private DetailConverter converter;

    @Override
    public String getDetailById(Long id) {
        return detailMapper.selectDetailById(id);
    }

    @Override
    public Long saveDetail(DetailAddModel detailAddModel) {
        DetailDO detailDO = converter.model2DO(detailAddModel);
        detailMapper.insert(detailDO);
        return detailDO.getId();
    }

    @Override
    public int deleteById(Long id) {
        return detailMapper.deleteById(id);
    }
}
